/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import Pojo.LoaiSPPojo;
import Pojo.NhanVienPojo;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author VUHOANG
 */
public class LoaiSPDao {
      
    public static ArrayList<LoaiSPPojo>DSLoaiSanPham()
    {
        ArrayList<LoaiSPPojo> ds=new ArrayList<LoaiSPPojo>();
        try {
            String sql="select * from loaisp";
            MySQLDataAccessHelper mysql=new MySQLDataAccessHelper();
            mysql.open();
            ResultSet rs=mysql.executeQuery(sql);            
            while(rs.next())
            {
               LoaiSPPojo nv=new LoaiSPPojo();
                 nv.setMaLoai(rs.getInt("MaLoai"));                
              nv.setTenLoai(rs.getString("TenLoai"));           
              
                ds.add(nv);
            }
            mysql.close();
            
        } catch (Exception e) {
       System.out.println(e.getMessage());
        }
        return ds;        
    }  
    public static ArrayList<LoaiSPPojo>DSLoaiSPTheoTen(String tennv)
    {
        ArrayList<LoaiSPPojo> ds =new ArrayList<LoaiSPPojo>();
        try 
        {
            String sql="select * from loaisp where ";
            MySQLDataAccessHelper mysql=new MySQLDataAccessHelper();
            mysql.open();
            ResultSet rs=mysql.executeQuery(sql);            
            while(rs.next())
            {
               LoaiSPPojo nv=new LoaiSPPojo();
                 nv.setMaLoai(rs.getInt("MaLoai"));                
              nv.setTenLoai(rs.getString("TenLoai"));      
              
                ds.add(nv);
            }
            mysql.close();            
        } catch (Exception ex) {
            System.out.println(ex);
        }        
        return ds;
    }
//     public static boolean ThemNhanVien(NhanVienPojo nv)
//    {
//        boolean kq=false;
////      try
////        {
//            MySQLDataAccessHelper dp=new MySQLDataAccessHelper();
//            dp.open();
//            String query=String.format("INSERT INTO nhanvien(`MANV`,`HONV`, `TENLOT`, `TENNV`, `NGSINH`, `DCHI`, `PHAI`, `LUONG`, `MA_NQL`, `PHG`)"
//                    + " VALUES ('"+ nv.getManv()+"','" + nv.getHonv()+"','"+ nv.getTenlot()+"','"+nv.getTennnv()+"','1989/12/12','"+nv.getDiachi()+"','"+nv.getPhai()+"','"+nv.getLuong()+"','"+nv.getMaNQL()+"','" + nv.getPhong()+ "')");
//            int n=dp.executeUpdate(query);
//            if(n==1)
//            {
//                kq=true;
//               // System.out.println("ko them dc!");
//            }
//            else
//            {
//                kq=false;
//                //System.out.println("them thanh cong!");
//            }
//            dp.close();    
//            return kq;
////        
////        }catch (SQLException ex) {
////            
////            System.out.println(ex);
////        } 
//    }
}
